Assignment #121 High Score
Code
///Name: Ian Grant
///Period:5
///Project Name: High Score
///File Name:HighScore.java
///05/28/16
import java.io.IOException;
import java.util.Scanner;
import java.io.PrintWriter;
public class HighScore {
public static void main(String[] args) {
Scanner stuff = new Scanner(System.in);
double score = 0;
String name = "";
System.out.println("Please enter your name: ");
name=stuff.next();
System.out.println("Please enter your power level: ");
score=stuff.nextInt();
PrintWriter fileOut;
try{
fileOut = new PrintWriter("receipt.txt");
} catch(IOException e) {
System.out.println("Sorry, I can't open the file 'receipt.txt' for editing.");
System.out.println("Maybe the file exists and is read-only?");
fileOut = null;
System.exit(1);
}
fileOut.println( "+------------------------+" );
fileOut.println( "| |" );
fileOut.println( "| High Score |" );
fileOut.println( "| |" );
fileOut.println( "| |" );
fileOut.println( "| Player: "+name+" |" );
fileOut.println( "| Power Level: "+score+" |" );
fileOut.println( "| |" );
fileOut.println( "+------------------------+" );
fileOut.close();
}
}
Output